﻿using Business.Base;
using Business.Base.Common;
using Business.Base.DB.DBRules;
using Business.Base.Enums;
using Business.Base.Model;
using Configuration;
using System;
using System.Collections.Generic;


namespace Business.CentrifugalPump.Perf
{
    [Serializable]
    [DBTableAttribute("centrifugalpump_perf_experiment")]
    public class CentrifugalPumpPerfExperiment : Experiment
    {

        #region 私有变量

        #region 试验基本信息
        String pumpModel;          //产品型号
        String pumpCode;           //产品编号
        String pumpName;           //水泵名字
        String manufacturer;       //生产商
        String customer;           //客户名,指要求水泵测试的客户的名字
        #endregion

        #region 泵参数

        double pumpRatedFlow;          //泵额定流量(m3/h)
        double pumpRatedHead;          //泵额定扬程(m)
        double pumpRatedPower;         //泵额定功率(kw)
        double pumpRatedEfficiency;    //泵额定效率(%)
        double dInlet;                 //进口表距(mm)
        double dOutlet;                //出口表距(mm)
        double impellerDia;            //叶轮直径(mm)
        #endregion
        
        #region 电机参数
        double motorRatedSpeed;         //电机额定转速（r/min）
        MotorRatedVoltage motorRatedVoltage;       //电机额定电压(V)
        double motorRatedCurrent;       //电机额定电流(A)
        double motorRatedEfficiency;    //电机效率(%)
        string motorWindingConnection;     //绕组接法
        string motorWindingMaterial;       //绕组材料
        #endregion

        #region 测试环境参数
        String flowmeter;               //选择的流量计
        int flowmeterAddress;           //流量计的DN地址
        double transformationRatio;     //电流变比

        double zInlet = Config.ZInlet;  //进口取压高度（表距）
        double zOutlet = Config.ZOutlet;  //出口取压高度（表距）

        double kInlet = Config.KInlet;   //进口摩擦系数
        double kOutlet = Config.KOutlet;  //出口摩擦系数
        #endregion

        #region 测试结果数据
        FlowHeadLevel experimentLevel;  //测试标准
                                        /*double experimentResultFlow;
                                        double experimentResultHead;
                                        double experimentResultPower;
                                        double experimentResultEff;
        bool experimentResultFlowIsPass;
        bool experimentResultHeadIsPass;
        bool experimentResultPowerIsPass;
        bool experimentResultEffIsPass;
                                        double crossFlow; //焦点流量
                                        double crossHead; //焦点扬程*/

        double measureHead = -1.0;      //实测扬程值，额定流量和额定扬程曲线和实测流量扬程拟合曲线交点的压力值
        double measureFlow = -1.0;      //实测流量，额定流量和额定扬程曲线和流量扬程拟合曲线交点的流量值
        double measurePower = -1.0;     //将measureFlow代入压力功率拟合曲线，算出的测量的功率值
        double measureEff = -1.0;       //将measureFlow代入压力效率拟合曲线，算出实测的效率值
        Boolean measureFlowIsPass;      //测量的流量值的测量值是否满足level的标准
        Boolean measureHeadIsPass;      //测量的扬程值的测量值是否满足level的标准

        Boolean measurePowerIsPass;     //测量的功率值的测量值是否满足level的标准
        Boolean measureEffIsPass;       //测量的效率值是否满足level的标准
        #endregion



        #endregion


        #region 根据规则生成的属性
        /// <summary>
        /// 出口取压长度，每个试验前录入，定死为出口管径的两倍
        /// </summary>
        [DBFieldAttribute("lOutlet")]
        public double LOutlet { get => 2 * DInlet; }
        /// <summary>
        /// 入口取压长度，每个试验前录入，定死为进口管径的两倍
        /// </summary>
        [DBFieldAttribute("lInlet")]
        public double LInlet { get => 2 * DOutlet; }




        #endregion

        #region 生成的属性
        [DBFieldAttribute("pumpRatedFlow")]
        public double PumpRatedFlow { get => pumpRatedFlow; set => pumpRatedFlow = value; }
        [DBFieldAttribute("pumpRatedHead")]
        public double PumpRatedHead { get => pumpRatedHead; set => pumpRatedHead = value; }
        [DBFieldAttribute("pumpRatedPower")]
        public double PumpRatedPower { get => pumpRatedPower; set => pumpRatedPower = value; }
  

        [DBFieldAttribute("pumpRatedEfficiency")]
        public double PumpRatedEfficiency { get => pumpRatedEfficiency; set => pumpRatedEfficiency = value; }
        [DBFieldAttribute("dInlet")]
        public double DInlet { get => dInlet; set => dInlet = value; }
        [DBFieldAttribute("dOutlet")]
        public double DOutlet { get => dOutlet; set => dOutlet = value; }
        [DBFieldAttribute("impellerDia")]
        public double ImpellerDia { get => impellerDia; set => impellerDia = value; }
        [DBFieldAttribute("motorRatedSpeed")]
        public double MotorRatedSpeed { get => motorRatedSpeed; set => motorRatedSpeed = value; }
        [DBFieldAttribute("motorRatedVoltage")]
        public MotorRatedVoltage MotorRatedVoltage { get => motorRatedVoltage; set => motorRatedVoltage = value; }
        [DBFieldAttribute("motorRatedCurrent")]
        public double MotorRatedCurrent { get => motorRatedCurrent; set => motorRatedCurrent = value; }
        [DBFieldAttribute("motorWindingConnection")]
        public string MotorWindingConnection { get => motorWindingConnection; set => motorWindingConnection = value; }
        [DBFieldAttribute("motorWindingMaterial")]
        public string MotorWindingMaterial { get => motorWindingMaterial; set => motorWindingMaterial = value; }
        [DBFieldAttribute("motorRatedEfficiency")]
        public double MotorRatedEfficiency { get => motorRatedEfficiency; set => motorRatedEfficiency = value; }
        [DBFieldAttribute("transformationRatio")]
        public double TransformationRatio { get => transformationRatio; set => transformationRatio = value; }
        [DBFieldAttribute("zInlet")]
        public double ZInlet { get => zInlet; set => zInlet = value; }
        [DBFieldAttribute("zOutlet")]
        public double ZOutlet { get => zOutlet; set => zOutlet = value; }
        [DBFieldAttribute("kInlet")]
        public double KInlet { get => kInlet; set => kInlet = value; }
        [DBFieldAttribute("kOutlet")]
        public double KOutlet { get => kOutlet; set => kOutlet = value; }
        [DBFieldAttribute("flowmeter")]
        public string Flowmeter { get => flowmeter; set => flowmeter = value; }
        [DBFieldAttribute("flowmeterAddress")]
        public int FlowmeterAddress { get => flowmeterAddress; set => flowmeterAddress = value; }

        [DBFieldAttribute("pumpModel")]
        public string PumpModel { get => pumpModel; set => pumpModel = value; }
        [DBFieldAttribute("pumpCode")]
        public string PumpCode { get => pumpCode; set => pumpCode = value; }
        [DBFieldAttribute("pumpName")]
        public string PumpName { get => pumpName; set => pumpName = value; }
        [DBFieldAttribute("manufacturer")]
        public string Manufacturer { get => manufacturer; set => manufacturer = value; }
        [DBFieldAttribute("customer")]
        public string Customer { get => customer; set => customer = value; }
        [DBFieldAttribute("experimentLevel")]
        public FlowHeadLevel ExperimentLevel { get => experimentLevel; set => experimentLevel = value; }
       
        #endregion










        /// <summary>
        /// 获取电参数的规则
        /// </summary>
        //[DBFieldAttribute("phassAddress")]
        public override int PhassAddress
        {
            get
            {
                DataSource[] dataSources = DataSource.DataSourceDic[DataSource.PHASEADDRESS];

                foreach (DataSource d in dataSources)
                {
                    if (int.Parse(d.BindMember) == (int)this.MotorRatedVoltage)
                    {
                        return (int)d.BindValue;
                    }
                }

                return -1;
                /*if (this.MotorRatedVoltage == MotorRatedVoltage.SinglePhase)
                {
                    return 448;
                }
                else
                {
                    return 544;
                }*/

            }
        }
      
        [DBFieldAttribute("measureHead")]
        public double MeasureHead { get => measureHead; set => measureHead = value; }
        [DBFieldAttribute("measureFlow")]
        public double MeasureFlow { get => measureFlow; set => measureFlow = value; }
        [DBFieldAttribute("measureEff")]
        public double MeasureEff { get => measureEff; set => measureEff = value; }
        [DBFieldAttribute("measurePower")]
        public double MeasurePower { get => measurePower; set => measurePower = value; }
        [DBFieldAttribute("measureHeadIsPass")]
        public bool MeasureHeadIsPass { get => measureHeadIsPass; set => measureHeadIsPass = value; }
        [DBFieldAttribute("measurePowerIsPass")]
        public bool MeasurePowerIsPass { get => measurePowerIsPass; set => measurePowerIsPass = value; }
        [DBFieldAttribute("measureEffIsPass")]
        public bool MeasureEffIsPass { get => measureEffIsPass; set => measureEffIsPass = value; }
        [DBFieldAttribute("measureFlowIsPass")]
        public bool MeasureFlowIsPass { get => measureFlowIsPass; set => measureFlowIsPass = value; }
    }
}
